<include file="default_header"/>
<body>
<div class="wraper">
    <div class="header bg-red">
        <p class="iconfont icon-iconfontrencopy"></p>
        <p>注册</p>
    </div>
    <div class="container">
        <p class="tips margin-b"></p>
        <div class="form-list margin-b clearfix">
            <span class="field pull-left">身份证</span>
            <input class="form-control pull-left" placeholder="请输入您的18位身份证" id="number" value="{BEESCRM:$user['number']}"/>
            <p class="tips-icon">
                <span class="iconfont icon-zhengque icon-green" id="right"></span>
                <span class="iconfont icon-cuowu icon-red" id="wrong"></span>
            </p>
        </div>
        <div class="form-list margin-b clearfix">
            <span class="field pull-left">姓名</span>
            <input class="form-control pull-left" placeholder="请输入您的真实姓名" id="real_name" value="{BEESCRM:$user['real_name']}"/>
            <p class="tips-icon">
                <span class="iconfont icon-zhengque icon-green" id="right"></span>
                <span class="iconfont icon-cuowu icon-red" id="wrong"></span>
            </p>
        </div>
        <div class="form-list margin-b clearfix">
            <span class="field pull-left">手机</span>
            <input class="form-control pull-left" placeholder="请输入您的手机号码" id="mobile" value="{BEESCRM:$user['mobile']}"/>
            <p class="tips-icon">
                <span class="iconfont icon-zhengque icon-green" id="right"></span>
                <span class="iconfont icon-cuowu icon-red" id="wrong"></span>
            </p>
        </div>
        <div class="form-list margin-b">
            <input class="form-control" placeholder="请输入验证码" id="smsVerifyCode"/>
            <a href="javascript:void(0);" class="btn" id="btn_verify">获取验证码</a>
        </div>
        <div class="btn-box margin-b">
            <a href="javascript:void(0);" class="btn register">提交</a>
        </div>
    </div>
	<input type="hidden" id="type" value="1">
    <if condition="$remark">
        <include file="remark"/>
    </if>
</div>

<include file="common_js"/>
<script>
    //点击获取验证码
    var verifyTag = true;
    $('.form-list').on('click', '#btn_verify', function (e) {
        e.preventDefault();
        if(verifyTag){
            getCode('#btn_verify');
        }
        else return;
    });
    function getCode(elem) {
        var tel = $('#mobile').val();
        var verify=/1[3-8]+\d{9}/;
        if (!verify.test(tel)) {
            $.alert('error','手机号码错误！');
            return false;
        } else {
            timeCountDown(elem);
            $.ajax({
                url: "/Base/User/sendText",
                type: "post",
                dataType: 'json',
                async: false,
                data: {
                    user_mobile: tel
                }
            });
        }
    }
    // 验证倒计时
    function timeCountDown(elem, seconds) {
        verifyTag = false;
        if(typeof seconds == undefined || seconds == null) seconds = 60;
        setTimeout(function () {
            if(seconds > 0) {
                seconds--;
                $(elem).text('已发送 ' + seconds + 's').addClass('disabled');
                timeCountDown(elem, seconds);
            } else {
                $(elem).removeClass('disabled').text('获取验证码');
                verifyTag = true;
            }
        }, 1000);
    }

    $('#mobile').bind('input propertychange', function() {
        var mobile = $("#mobile").val();
        if($.validatePhoneNumber(mobile)){
            $(this).siblings().find('.iconfont').hide();
            $(this).siblings().find('#right').show();
        }else{
            $(this).siblings().find('.iconfont').hide();
            $(this).siblings().find('#wrong').show();
        }
    });


    var height = $(window).height();
    var bottombox_height = $('.bottom-box').outerHeight();
    $('.wraper').css("minHeight", height);
    $('.wraper').css("paddingBottom", bottombox_height);

    $(document).on('click','.register',function(){
        var data = {};
        var verify_method = /^(?:13\d|15\d|18\d|17\d|14\d)\d{5}(\d{3}|\*{3})$/;

        data.number = $('#number').val().toLowerCase();
        data.mobile = $('#mobile').val();
        data.real_name = $('#real_name').val();
        data.type = $('#type').val();
        data.code = $('#smsVerifyCode').val();

        if (!data.number) {
            $.alert('error','身份证号码不能为空！');
            return false;
        }
        /* else {
            var codeValid = IdentityCodeValid(data.number);
            if (codeValid['errCode'] == '1000') {
                $.alert('error','身份证不合法！');
                return false;
            }
        } */
        
        if (!data.real_name) {
            $.alert('error', '姓名不能为空');
            return false;
        } else if (!data.mobile) {
            $.alert('error', '手机号不能为空');
            return false;
        } else if (!verify_method.test(data.mobile)) {
            $.alert('error', '请输入正确的手机号');
            return false;
        }else if (!data.code) {
            $.alert('error', '请输入验证码');
            return false;
        }
        var json = {};
        json.method = 'post';
        json.type = 'json';
        json.url = "{BEESCRM::U('/base/User/doRegister',array('account_id'=>$accountId ,'type' => $type))}";
        json.data = data;
        $.getAjax(json, true, reload, '');
    });

    function reload(data) {
        var type = data.type;
        location.href = "{BEESCRM::U('/base/User/tips',array('account_id'=>$accountId))}/type/" + type;
        //setTimeout("location.href ='{BEESCRM::U('base/center/center',array('wechat_id'=>$wechat_id))}'", 2000);
    }


        //身份证号合法性验证 
        //支持15位和18位身份证号
        //支持地址编码、出生日期、校验位验证
        function IdentityCodeValid(code) {
            var city = {11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江 ", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北 ", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏 ", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外 "};
            var tip = "";
            var pass = true;

            if(!code) {
                tip = "身份证格式错误";
                pass = false;
            }
            if (!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)) {
                tip = "身份证号格式错误";
                pass = false;
            }
            else if (!city[code.substr(0, 2)]) {
                tip = "地址编码错误";
                pass = false;
            }
            else {
                //18位身份证需要验证最后一位校验位
                if (code.length == 18) {
                    code = code.split('');
                    //∑(ai×Wi)(mod 11)
                    //加权因子
                    var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
                    //校验位
                    var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
                    var sum = 0;
                    var ai = 0;
                    var wi = 0;
                    for (var i = 0; i < 17; i++)
                    {
                        ai = code[i];
                        wi = factor[i];
                        sum += ai * wi;
                    }
                    var last = parity[sum % 11];
                    if (parity[sum % 11] != code[17]) {
                        tip = "校验位错误";
                        pass = false;
                        }
                    }
            }

            if (!pass) {
                return {'errCode': 1000, 'errMsg': tip};
            } else {
                return {'errCode': 200, 'errMsg': 'success'};
            }
        }
</script>
</body>
</html>